import time

from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
class Base():
    def __init__(self,driver):
        self.driver=driver
    def goto(self,url):
        self.driver.get(url)
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver:driver.find_element(*loc).is_displayed)
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
    def click(self,loc):
        self.find_element(loc).click()
    def text(self,loc):
        return self.find_element(loc).text
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    def frame(self,loc):
        self.driver.switch_to.frame(self.find_element(loc))
    def tframe(self):
        self.driver.switch_to.default_content()
#   弹框
    def tk(self):
        allert=self.driver.switch_to.alert
        allert.accept()
#   下拉框
    def xlk(self,loc,x):
        select=Select(self.driver.find_element(loc))
        select.select_by_index(x)
    # 切换
    def qh(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    # 鼠标事件
    def shubiap(self):
        ActionChains(self.driver).double_click().perform()
    # 浏览器
    def sx(self):
        self.driver.refresh()
    # 滚动
    def gd(self):
        self.driver.execute_script('window.scrollTo(0,1000)')
    # 键盘
    def jp(self,loc):
        self.find_element(loc).send_keys(Keys.CONTROL,'x')